/**
 * @author Koszti Lajos [Ajnasz] http://ajnasz.hu ajnasz@ajnasz.hu
 * @licence GPL v2
 */
// mozilla preferences component service
var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
/**
 * returns the specified extension preference
 */
var getPref = {
  checkFreq : function() {
    return prefManager.getIntPref('extensions.wsnotifier.checkfreq');
  },
  openInNewTab : function(value) {
    return prefManager.getBoolPref('extensions.wsnotifier.openinnewtab');
  },

  rememberLogin : function(value) {
    return prefManager.getBoolPref('extensions.wsnotifier.rememberLogin');
  },

  activateOpenedTab : function(value) {
    return prefManager.getBoolPref('extensions.wsnotifier.activateopenedtab');
  },
  
  showNotificationWindow : function(value) {
    return prefManager.getBoolPref('extensions.wsnotifier.shownotificationwindow');
  },
  
  userName : function(value) {
    return prefManager.getCharPref('extensions.wsnotifier.username');
  }
};
/**
 * set the specified extension preference
 */
var setPref = {
  checkFreq : function(value) {
    prefManager.setIntPref('extensions.wsnotifier.checkfreq', value);
  },
  openInNewTab : function(value) {
    prefManager.setBoolPref('extensions.wsnotifier.openinnewtab', value);
  },
  rememberLogin : function(value) {
    prefManager.setBoolPref('extensions.wsnotifier.rememberLogin', value);
  },
  
  activateOpenedTab : function(value) {
    prefManager.setBoolPref('extensions.wsnotifier.activateopenedtab', value);
  },
  showNotificationWindow : function(value) {
   prefManager.setBoolPref('extensions.wsnotifier.shownotificationwindow', value);
  },
  
  userName : function(value) {
   prefManager.setCharPref('extensions.wsnotifier.username', value);
  }
};
/**
 * save the preferences into the chrome when the pref dialog is accepted
 */
var savePreferences = function() {
  setPref.checkFreq(document.getElementById('WSN-checkfreq-field').value);
  setPref.openInNewTab(document.getElementById('WSN-openinnewtab-field').checked);
  setPref.resetCounter(document.getElementById('WSN-resetcounter-field').checked);
  setPref.rememberLogin(document.getElementById('WSN-rememberLogin-field').checked);
  //setPref.leftClickOpen(document.getElementById('GRW-leftclickopen-field').value);
  setPref.activateOpenedTab(document.getElementById('WSN-activateopenedtab-field').checked);
  setPref.showNotificationWindow(document.getElementById('WSN-shownotificationwindow-field').checked);

  setPref.userName(document.getElementById('WSN-accountmanage-login').value);
  passwordManager.addPassword(document.getElementById('WSN-accountmanage-pass').value);

};
/**
 * sets the values on the pref dialog when it opens
 */
var setPrefPaneVals = function() {
  document.getElementById('WSN-checkfreq-field').value = getPref.checkFreq();
  document.getElementById('WSN-openinnewtab-field').checked = getPref.openInNewTab();
  document.getElementById('WSN-resetcounter-field').checked = getPref.resetCounter();

  document.getElementById('WSN-rememberLogin-field').checked = getPref.rememberLogin();
  //document.getElementById('GRW-leftclickopen-field').value = getPref.leftClickOpen();
  document.getElementById('WSN-activateopenedtab-field').checked = getPref.activateOpenedTab();
  document.getElementById('WSN-accountmanage-pass').value = passwordManager.getPassword();
  document.getElementById('WSN-accountmanage-login').value = getPref.userName();
  document.getElementById('WSN-shownotificationwindow-field').checked = getPref.showNotificationWindow();
};
/**
 * show/hide the newtab options
 */
var openNewTabCheckToogle = function() {
  var cbfield = document.getElementById('WSN-openinnewtab-field');
  if(cbfield.checked) {
    document.getElementById('WSN-activateopenedtab-field').disabled = '';
    //document.getElementById('GRW-leftclickopen-field').disabled = '';
    //document.getElementById('GRW-leftclickopen-label').disabled = '';

    document.getElementById('WSN-openinnewtab-options').style.display = '';
  }
  else {
    document.getElementById('WSN-activateopenedtab-field').disabled = 'disabled';
    //document.getElementById('GRW-leftclickopen-field').disabled = 'disabled';
    //document.getElementById('GRW-leftclickopen-label').disabled = 'disabled';
    document.getElementById('WSN-openinnewtab-options').style.display = 'none';
  }
};
